<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // Object.defineProerty(obj,propName,{})
        //  - 主要对一个已经存在的对象中的属性进行修改

        const obj = {
            name: 'laowang',
            age: 18
        }

        Object.defineProperty(obj,'name',{
            value:'laowang',
            writable:true,
            enumerable:false,
            configurable:false
        })

        obj.name = 'llll'
        console.log(obj);

        // getter setter 存取器属性
        Object.defineProperty(obj,'age',{
            get(){
                console.log('获取值');
                return 18
            },
            set(newVal){
                console.log('值更新了',newVal)
            }

        })

        obj.age++
    </script>
</body>

</html>